package com.itheimaoa.service.process.impl;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.itheimaoa.domain.process.Exam;
import com.itheimaoa.service.base.impl.CommonServiceImpl;
import com.itheimaoa.service.process.IExamService;

@Service
@Transactional
public class ExamServiceImpl extends CommonServiceImpl<Exam> implements IExamService {
	@Override
	@Transactional(readOnly = true)
	public Exam findApplyId(String applyId) {
		String jpql = " from Exam o where o.apply.aid = ? order by o.uptime desc";
		List<Exam> exams = this.hibernateTemplate.find(jpql, applyId);
		if (exams != null && exams.size() > 0) {
			exams.get(0);
		}
		return null;
	}

	@Override
	@Transactional(readOnly = true)
	public Exam findExamByApplyId(String applyId) {
		String jpql = " from Exam o where o.apply.aid = ?";
		List<Exam> exams = this.hibernateTemplate.find(jpql, applyId);
		if (exams != null && exams.size() > 0) {
			for (Exam e : exams) {
				if (!e.getAgree()) {
					return e;
				}
			}
		}
		return null;
	}

	@Override
	@Transactional(readOnly = true)
	public List<Exam> findExamsByApplyId(String applyId) {
		String jpql = " from Exam o where o.apply.aid = ? order by o.uptime asc";
		List<Exam> exams = this.hibernateTemplate.find(jpql, applyId);
		return exams;
	}

}
